<template>
  <el-form
    :model="ruleForm"
    status-icon
    :rules="rules"
    ref="ruleForm"
    label-width="100px"
    class="demo-ruleForm"
  >
    <p style="margin:0 0 20px 0">
      Quick application for audit Fill out the form and we will contact you
      within half an hour
    </p>
    <el-form-item label="github/address" prop="github">
      <el-input
        v-model="ruleForm.github"
        autocomplete="off"
        placeholder="input your github or address"
      ></el-input>
    </el-form-item>
    <el-form-item label="email" prop="email">
      <el-input
        v-model="ruleForm.email"
        autocomplete="off"
        placeholder="input your email"
      ></el-input>
    </el-form-item>
    <el-form-item label="telegram" prop="telegram">
      <el-input
        v-model.number="ruleForm.telegram"
        placeholder="input your telegram"
      ></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">send</el-button>
      <span
        >I agree to the
        <router-link target="_blank" to="/about">Privacy Policy</router-link>
        аnd to receive email from atoms</span
      >
    </el-form-item>
  </el-form>
</template>
<script>
import { addTel } from "@/config/api";
export default {
  data() {
    var checktelegram = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("telegram can not be null"));
      }
      setTimeout(() => {
        callback();
      }, 1000);
    };
    var validategithub = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("enter github"));
      } else {
        if (this.ruleForm.email !== "") {
          this.$refs.ruleForm.validateField("email");
        }
        callback();
      }
    };

    return {
      ruleForm: {
        github: "",
        email: "",
        telegram: ""
      },
      rules: {
        // github: [{ validator: validategithub, trigger: "blur" }],
        //email: [{ validator: validategithub2, trigger: "blur" }],
        //telegram: [{ validator: checktelegram, trigger: "blur" }]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          const res = await this.httpPost(addTel, this.ruleForm);
          //alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>
